package storage

import (
    clientv3 "go.etcd.io/etcd/client/v3"
    "time"
)

const (
    taskTypePrefix = "tasktype"
    taskPrefix     = "task"
    planPrefix     = "plan"
    planLogPrefix  = "planlog"
)

var client *clientv3.Client

func InitEtcd() {
    cli, err := clientv3.New(clientv3.Config{
        Endpoints:   []string{"cing-etcd.cing-system:2379"},
        DialTimeout: 10 * time.Second,
    })
    if err != nil {
        panic(err.Error())
    } else {
        client = cli
    }
}

func Etcd() *clientv3.Client {
    return client
}

func WithPrefixEnd() []clientv3.OpOption {
    return []clientv3.OpOption{
        clientv3.WithPrefix(),
        clientv3.WithSort(clientv3.SortByKey, clientv3.SortDescend),
        clientv3.WithLimit(1),
    }
}
